<template>


  <div class="app-container">
    <div style="margin-bottom: 20px">
      <h1>根据公告的标题或者内容进行模糊搜索:</h1>
      标题:<input style="width: 20%;height:30px;padding: 10px;margin-right: 3%" v-model="searchData.title"/>
      内容:<input style="width: 20%;height:30px;padding: 10px;margin-right: 25px" v-model="searchData.content"/>
      <el-button @click="loadData()" style="height: 40px">搜索</el-button>



    </div>
    <el-table
      v-loading="listLoading"
      :data="list"
      element-loading-text="Loading"
      border
      fit
      highlight-current-row
      :default-sort = "{prop: 'id', order: 'descending'}"
    >
      <el-table-column align="center" label="序号" prop="id"></el-table-column>
      <el-table-column align="center" label="标题" prop="title"></el-table-column>
      <el-table-column align="center" label="内容" :show-overflow-tooltip="true" prop="content"></el-table-column>
      <el-table-column type="text"  align="center"  label="日期" prop="cdate"></el-table-column>

      <el-table-column
        fixed="right"
        label="操作"
        width="100">
        <template slot-scope="scope">
          <el-button type="text" @click="update(scope.row)" size="small">修改</el-button>
          <el-button @click="del(scope.row.id)" type="text" size="small">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <div style="margin-top: 10px;text-align: center;align-items: center">
      <el-pagination
        background
        layout="prev, pager, next"
        :page-count="pages"
        v-model:current-page="this.currpage"
        @current-change="loadData"/>
    </div>
  </div>
</template>

<script>
import request from '@/utils/request'

export default {
  filters: {
    statusFilter(status) {
      const statusMap = {
        published: 'success',
        draft: 'gray',
        deleted: 'danger'
      }
      return statusMap[status]
    }
  },
  data() {
    return {
      currpage:1,
      list: [],
      listLoading: false,
      pages:1,
      searchData:{
        title:"",
        content:""
      }
    }
  },
  mounted() {
    this.loadData()
  },
  methods: {




    passFormat(row, column) {
      //const pass = row[column.property]
      return "******";
    },





    loadData(rp=1){
      this.currpage = rp;

      console.log(this.currpage);
      //请求接口 实现数据的查询
      this.listLoading = true


      request({
        url:"/library/announcement/querypage.do?page="+this.currpage+"&size=1"+"&title="+this.searchData.title+"&content="+this.searchData.content
      }).then(res=>{
        console.log(res)
        this.list=res.data.list;
        this.pages=res.data.pages;
        this.listLoading=false;
      })
    },
    del(id){
      this.$confirm('亲，是否确认删除吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        //请求接口 实现数据的删除
        request({
          url:"/library/announcement/del.do?id="+id
        }).then(res=>{
          if(res.code==0){
            this.$message({
              type: 'success',
              message: '删除成功!'
            });
            this.loadData();
          }
        })

      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },
    update(obj){
          this.$router.push({path:"/announcementupdate",query: {msg:obj}});



    }
  }
}
</script>
